package org.link.bean;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 * 
 * project_name:hibernate_annotation
 * package_name:org.link.bean
 * file_name:ClassRoom.java
 * @author Link
 * create_date:2015年12月15日 上午9:40:44
 * modified_date:
 * description:班级实体类
 *
 */
@Entity
@Table(name="t_classroom")
public class ClassRoom {

	@Id
	@GenericGenerator(name="systemUUID",strategy="uuid")
	@GeneratedValue(generator="systemUUID")
	@Column(name = "cid", insertable = true, updatable = true, nullable = false,length=36)
	private String cid;
	@Column(name="cname",length=50)
	private String cname;
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="pid")
	private Special special;
	
	@OneToMany(mappedBy="classRoom")//配置双向映射,mappedBy指向维护的关系键(在这里即指向Student中的classRoom属性)
	@LazyCollection(LazyCollectionOption.EXTRA)//主要用于当查询这个班级有多少个学生时候减少hibernate查询语句(在这里只会有一条count(*))
	private Set<Student> students;
	
	public ClassRoom() {
		super();
	}

	public ClassRoom(String cid) {
		super();
		this.cid = cid;
	}

	public ClassRoom(String cname, Special special) {
		super();
		this.cname = cname;
		this.special = special;
	}


	public ClassRoom(String cid, String cname, Special special) {
		super();
		this.cid = cid;
		this.cname = cname;
		this.special = special;
	}

	public String getCid() {
		return cid;
	}

	public void setCid(String cid) {
		this.cid = cid;
	}

	public String getCname() {
		return cname;
	}

	public void setCname(String cname) {
		this.cname = cname;
	}

	public Special getSpecial() {
		return special;
	}

	public void setSpecial(Special special) {
		this.special = special;
	}

	public Set<Student> getStudents() {
		return students;
	}

	public void setStudents(Set<Student> students) {
		this.students = students;
	}

	@Override
	public String toString() {
		return "ClassRoom [cid=" + cid + ", cname=" + cname + ", special=" + special + "]";
	}
	
	
	
}
